package com.neoCalf.neoUser.webSocket.handler;


import com.neoCalf.neoUser.webSocket.tool.ChannelContextUtils;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
@ChannelHandler.Sharable
@Slf4j
public class HandlerHeartBeat extends ChannelDuplexHandler {
    @Resource
    private ChannelContextUtils channelContextUtils;

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent stateEvent = (IdleStateEvent) evt;
            if (stateEvent.state() == IdleState.READER_IDLE) {
                log.info("心跳超时");
                ctx.close();
            }
        }
    }
}
